package com.example.controller;

import com.example.service.ServerService;
import org.apache.mina.core.session.IoSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

@RestController
public class TestController {

    Logger logger = LoggerFactory.getLogger(getClass());

    @Resource
    private ServerService serverService;

    @RequestMapping("getSize")
    public int getSize() {
        return serverService.getAcceptor().getManagedSessionCount();
    }

    @RequestMapping("getSessionMap")
    public void getSessionMap() {
        Map<Long, IoSession> maps = serverService.getAcceptor().getManagedSessions();
        for (IoSession ioSession : maps.values()) {
            logger.warn("session: " + ioSession.getId());
        }
    }
}
